// Package prometheus
// Created by GoLand
// @User: lenora
// @Date: 2024/7/29
// @Time: 17:39

package prometheus

import (
	"camp/microbook/internal/service/sms"
	"context"
	"github.com/prometheus/client_golang/prometheus"
	"time"
)

type Service struct {
	svc    sms.Service
	vector *prometheus.SummaryVec
}

func NewService(svc sms.Service, opts prometheus.SummaryOpts) sms.Service {
	ve := prometheus.NewSummaryVec(opts, []string{"tpl_id"})
	prometheus.MustRegister(ve)
	return &Service{
		svc:    svc,
		vector: ve,
	}
}

func (s *Service) Send(ctx context.Context, tplId string, args []string, phone ...string) error {
	start := time.Now()
	defer func() {
		duration := time.Since(start)
		s.vector.WithLabelValues(tplId).Observe(float64(duration.Milliseconds()))
	}()
	return s.svc.Send(ctx, tplId, args, phone...)
}
